package com.csglxt.view.action;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.csglxt.base.BaseAction;
import com.csglxt.domain.Order;
import com.csglxt.domain.OrderItem;
import com.csglxt.utils.QueryHelper;
import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * @ClassName: OrderAction
 * @Description: TODO(订单管理控制器 （查询）)
 * @author Itchbeilef
 * @date 2015-5-28 下午9:32:16
 * 
 */
@Controller
@Scope("prototype")
@SuppressWarnings("serial")
public class OrderAction extends BaseAction<Order> {
    String GoodsName;
    String goodsCateId;
    Date kdate;
    Date jdate;

    /**
     * 
     * @Title: list
     * @Description: TODO(单据列表(带时间、单据类型查询))
     * @param
     * @return
     * @throws
     */
    public String list() {
        QueryHelper qureyHelper = new QueryHelper(Order.class, "ord")
                .addOrderProperty("date", false);
        if (model.getDealType() != null
                && !model.getDealType().equals(new BigDecimal(0))) {
            qureyHelper.addCondition(" ord.dealType = ? ", model.getDealType());
        }
        if (kdate != null && jdate != null) {
            qureyHelper.addCondition(" ord.date >= ? ", kdate);
            qureyHelper.addCondition(" ord.date <= ? ", jdate);
        }
        ActionContext.getContext().put("dealTypelist",
                Arrays.asList("1", "2", "3", "4"));
        qureyHelper.preparePageBean(orderService, pageNum, pageSize);
        return "list";
    }

    /**
     * 
     * @Title: itemlist
     * @Description: TODO(单据子项列表(带商品搜索 商品分类搜索))
     * @param
     * @return
     * @throws
     */
    public String itemlist() {
        QueryHelper qureyHelper = new QueryHelper(OrderItem.class, "i");
        Order order = null;
        if (model.getId() != null) {
            qureyHelper.addCondition(" i.order = ? ", model);
        } else {
            return null;
        }
        if (goodsCateId != null && !goodsCateId.isEmpty()
                && !goodsCateId.equals("0")) {
            qureyHelper.addCondition(" i.goods.goodsCate.id = ? ", goodsCateId);
        }
        if (GoodsName != null && !GoodsName.isEmpty()) {
            qureyHelper.addCondition("i.goods.name like ?", "%" + GoodsName
                    + "%");
        }
        ActionContext.getContext().put("goodsCateList",
                goodsCateService.findAll());
        qureyHelper.preparePageBean(orderService, pageNum, pageSize);
        order = orderService.getById(model.getId());
        ActionContext.getContext().put("order", order);
        return "itemlist";
    }

    public String getGoodsName() {
        return GoodsName;
    }

    public void setGoodsName(String goodsName) {
        GoodsName = goodsName;
    }

    public String getGoodsCateId() {
        return goodsCateId;
    }

    public void setGoodsCateId(String goodsCateId) {
        this.goodsCateId = goodsCateId;
    }

    public Date getKdate() {
        return kdate;
    }

    public void setKdate(Date kdate) {
        this.kdate = kdate;
    }

    public Date getJdate() {
        return jdate;
    }

    public void setJdate(Date jdate) {
        this.jdate = jdate;
    }
}
